﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;

using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Task5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void butLogin_Click(object sender, EventArgs e)
        {

             //获取用户输入的用户名和密码
             //取得画面控件的值
             string userName1 = this.txtText1.Text;
             string usePwd1 = this.txtText2.Text;
             //非空验证
            if (userName1 == "" || usePwd1 == "")
            {
                MessageBox.Show("用户名或密码不能为空！", "验证错误：", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //根据登录名查询用户信息
                string sql = string.Format("select * from usesInfo where usesName='{0}' and usePwd='{1}'", userName1, usePwd1);
                SqlDataReader dr = DBHelper.GetDataReader(sql);
                int count = 0;
                while (dr.Read())
                {
                    string UserName2 = dr["usesName"].ToString();
                    string UsePwd2 = dr["usePwd"].ToString();
                    if (userName1 == UserName2 && usePwd1 == UsePwd2) 
                    {
                        count = 1;
                    }
                }
                dr.Close();
                if (count == 1)
                {
                    MessageBox.Show("登录成功");
                }
                else
                {
                    MessageBox.Show("登录失败");
                }
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

        //private void Form1_Load(object sender, EventArgs e)
        //{

       // }
  
